<?php 
    $videoid = $_POST['videoid'];
	$period = $_POST["period"];
	$time = date("y-m-d h:i:s");
    $ip = getUserIP();
    require('config.php');
    $stmt = $connection->prepare('insert into anonymous_user_watch_video (ip, time, period, videoid) values (?, ?, ?, ?)');
    $stmt->bind_param("ssds", $ip, $time, $period, $videoid);
    $stmt->execute();

    function getUserIP()
    {
        if(!empty($_SERVER["HTTP_CLIENT_IP"]))  
            $cip = $_SERVER["HTTP_CLIENT_IP"];  
        else if(!empty($_SERVER["HTTP_X_FORWARDED_FOR"]))  
            $cip = $_SERVER["HTTP_X_FORWARDED_FOR"];  
        else if(!empty($_SERVER["REMOTE_ADDR"]))  
            $cip = $_SERVER["REMOTE_ADDR"];  
        else  
            $cip = "无法获取！";  
        return $cip;  
    }
?> 
